const subwayDatas = require('../datas/subway_datas.js');
let app = getApp();
Page({
  data: {
    cityArr: ['武汉'],
    lineArr: ['1号线', '2号线', '3号线', '4号线', '5号线', '6号线', '7号线', '8号线', '11号线', '16号线', '阳逻线'],
    cityIndex: 0,
    lineIndex: 0,
    subwayDataList: [],
    stationDatas: [],
    keyword: ""
  },
  onLoad: function(options) {
    this.setData({
      subwayDataList: subwayDatas.subwayDatas,
    });
    this.searchStationDatas('');
  },
  // 查询站点信息
  searchStationDatas (stationName) {
    let lineObj = subwayDatas.subwayDatas[this.data.cityIndex].lines[this.data.lineIndex];
    let tempStations = [];
    
    // 确定站点颜色和展现数据
    for (const key in  lineObj.stations) {
      let stObj = lineObj.stations[key];
      stObj.lineColor = lineObj.lineColor;
      stObj.linePng = lineObj.lineColor.replace("#","");
      if (stationName != '') {
        if (stObj.zdName.indexOf(stationName) > -1) {
          tempStations.push(stObj);
        }
      } else {
        tempStations.push(stObj);
      }
    }

    this.setData({
      stationDatas: tempStations
    });
    app.data.lineColor = lineObj.lineColor;
  },
  bindCityChange: function(e) {
    this.setData({
      cityIndex: e.detail.value
    })
  },
  bindLineChange: function(e) {
    this.setData({
      lineIndex: e.detail.value
    });
    this.searchStationDatas('');
  },
  bindSearchStatios() {
    this.searchStationDatas(this.data.keyword)
  }
})
